# -*- coding:utf8 -*-
import Image
import os

def reConstruct_folder(src_folder,res_folder,res_size):
    flag=1
    for src_img in os.listdir(src_folder):
        src_img_path = src_folder + "\\" + src_img
        res_img_path = res_folder + "\\" + src_img
        im = Image.open(src_img_path)
        new_im = im.resize(res_size)
        new_im.save(res_img_path)
        flag +=1
        if flag%100 == 0:
            print "num:" + str(flag)

def reConstruct_single(src_path,res_path,res_size):
    src_img_path = src_path
    res_img_path = res_path
    im = Image.open(src_img_path)
    new_im = im.resize(res_size)
    new_im.save(res_img_path)
    print "done"

def reName(src_folder,res_folder):
    flag=1
    for src_img in os.listdir(src_folder):
        src_img_path = src_folder + "\\" + src_img
        res_img_path = res_folder + "\\" + str(flag)+".jpg"
        im = Image.open(src_img_path)
        im.save(res_img_path)
        flag += 1
        if flag%100==0:
            print "done:"+str(flag)


if __name__ == '__main__':
    """
    reConstruct_folder("C:\\Users\\wuxiaomin\\Desktop\\arobei\\neg_new",\
                "C:\\Users\\wuxiaomin\\Desktop\\arobei\\pos_64_new",(64,64))
    """
    reConstruct_single("C:\\Users\\wuxiaomin\\Desktop\\arobei\\tea_detect\\src\\shiyaqiang\\P50805-172644.jpg",\
                       "C:\\Users\\wuxiaomin\\Desktop\\arobei\\tea_detect\\src\\shiyaqiang\\P50805-172644-half.jpg",\
        (984,984))
    """
    reName("C:\\Users\\wuxiaomin\\Desktop\\arobei\\src","C:\\Users\\wuxiaomin\\Desktop\\arobei\\src_new")
    """